<?php

namespace App\Http\Controllers\Api;

use App\Model\Lesson;
use App\Model\LessonTag;
use App\Model\Slider;
use App\Model\Tag;
use App\Model\Video;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ContentController extends CommonController
{
    public function getSlider(){
        //获取轮播图数据中is_show等于1的轮播图数据
        $sliders = Slider::where('is_show',1)->get();
        //将获取的图片数据返回
        return $sliders;
    }
//    获取所有标签
    public function tags()
    {
        return $this->response(Tag::get());
    }

//    课程列表
    public function lesson($tid)
    {
        if ($tid) {
            $lessonids = LessonTag::where('tag_id', $tid)->pluck('lesson_id');
            //找到所有对应课程数据
            $data = Lesson::whereIn('id', $lessonids)->get();
        } else {
            $data = Lesson::get();
        }
        return $this->response($data);
    }

//    获取推荐视频
    public function commendLesson($row){
        $data=Lesson::where('iscommend',1)->limit($row)->get();
        return $this->response($data);
    }

//    获取热门视频
    public function hotLesson($row){
        $data=Lesson::where('ishot',1)->limit($row)->get();
        return $this->response($data);
    }

//    获取视频列表
    public function videos($lessonId){
        $data=Video::where('lesson_id',$lessonId)->get();
        return $this->response($data);
    }



}
